package com.ymatou.iapi.usersafe.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.login.service.LoginAuthCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.usersafe.parameter.IpAreaAuthManageRequestDtoBean;
import com.ymatou.iapi.usersafe.service.IpAreaAuthManageRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.sqlwapper.UserSafeWapper;
/**
*更新用户的所有IP区域认证状态为已认证
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_IpAreaAuthManageRequestDto{
	private static IpAreaAuthManageRequestDtoBean ipareaauthmanagerequestdtoBean;
	private static IpAreaAuthManageRequestDtoCall ipareaauthmanagerequestdtoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("更新用户的所有IP区域认证状态为已认证");
	}

	@Before
	public void caseUp() {
		ipareaauthmanagerequestdtoBean=new IpAreaAuthManageRequestDtoBean();
		ipareaauthmanagerequestdtoCall=new IpAreaAuthManageRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(ipareaauthmanagerequestdtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_IpAreaAuthManageRequestDto_001() {
		Logger.start(true,"更新买手用户的所有IP区域认证状态为已认证成功");
		try {
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer userid=uc.getUserid();
			new UserSafeWapper().updateAuthStatus(userid, null, null, null, 0);
			List<Map<String, Object>> listold = new UserSafeWapper().getIPAuthByUserIdAndAreas(userid, null, null, null);
			Logger.debug(listold);
			Thread.sleep(2000);
			String oldauthTime=listold.get(0).get("AuthTime").toString();
			String country=listold.get(0).get("Country").toString();
			String province=listold.get(0).get("Province").toString();
			String city=listold.get(0).get("City").toString();
			ipareaauthmanagerequestdtoBean.setCountry(country);
			ipareaauthmanagerequestdtoBean.setProvince(province);
			ipareaauthmanagerequestdtoBean.setCity(city);
			ipareaauthmanagerequestdtoBean.setUserId(userid);
			ipareaauthmanagerequestdtoCall.setData(ipareaauthmanagerequestdtoBean);
			ipareaauthmanagerequestdtoCall.callService();			
			Logger.verifyEquals("true", ipareaauthmanagerequestdtoCall.getString("Success"), "验证Success");
			List<Map<String, Object>> list = new UserSafeWapper().getIPAuthByUserIdAndAreas(userid, null, null, null);
			for (Map<String, Object> map : list) {
				if(map.get("Country").equals(country)&&map.get("Province").equals(province)&&map.get("City").equals(city)){
					Logger.verifyEquals(200, map.get("AuthStatus"), "验证AuthStatus");
					Logger.verifyNotEquals(oldauthTime, map.get("AuthTime").toString(), "验证AuthTime");
				}
			}
			LoginAuthCall loginc= new JUserCallService().login(urb.getLoginId(), urb.getPas(), "app", urb.getClientIp(), urb.getDeviceId());
			Logger.verifyEquals(true, loginc.getSuccess(), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_IpAreaAuthManageRequestDto_002() {
		Logger.start(false,"缺少参数UserId,失败");
		try {
			ipareaauthmanagerequestdtoCall.setData(ipareaauthmanagerequestdtoBean);
			ipareaauthmanagerequestdtoCall.callService();			
			Logger.verifyIsContains("非法的用户ID", ipareaauthmanagerequestdtoCall.getReturnData(), "验证返回信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_IpAreaAuthManageRequestDto_003() {
		Logger.start(true,"更新买家用户的所有IP区域认证状态为已认证成功");
		try {
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			urb.setRegisterType(1);
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer userid=uc.getUserid();
			List<Map<String, Object>> listold = new UserSafeWapper().getIPAuthByUserIdAndAreas(userid, null, null, null);
			String oldauthTime=listold.get(0).get("AuthTime").toString();
			String country=listold.get(0).get("Country").toString();
			String province=listold.get(0).get("Province").toString();
			String city=listold.get(0).get("City").toString();
			Thread.sleep(2000);
			ipareaauthmanagerequestdtoBean.setCountry(country);
			ipareaauthmanagerequestdtoBean.setProvince(province);
			ipareaauthmanagerequestdtoBean.setCity(city);
			ipareaauthmanagerequestdtoBean.setUserId(userid);
			ipareaauthmanagerequestdtoCall.setData(ipareaauthmanagerequestdtoBean);
			ipareaauthmanagerequestdtoCall.callService();			
			Logger.verifyEquals("true", ipareaauthmanagerequestdtoCall.getString("Success"), "验证Success");
			List<Map<String, Object>> list = new UserSafeWapper().getIPAuthByUserIdAndAreas(userid, null, null, null);
			for (Map<String, Object> map : list) {
				if(map.get("Country").equals(country)&&map.get("Province").equals(province)&&map.get("City").equals(city)){
					Logger.verifyEquals(200, map.get("AuthStatus"), "验证AuthStatus");
					Logger.verifyNotEquals(oldauthTime, map.get("AuthTime").toString(), "验证AuthTime");
				}
			}
			LoginAuthCall loginc= new JUserCallService().login(urb.getLoginId(), urb.getPas(), "app", urb.getClientIp(), urb.getDeviceId());
			Logger.verifyEquals(true, loginc.getSuccess(), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_IpAreaAuthManageRequestDto_004() {
		Logger.start(true,"Country为空,失败");
		try {
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer userid=uc.getUserid();
			ipareaauthmanagerequestdtoCall.setData(ipareaauthmanagerequestdtoBean);
			ipareaauthmanagerequestdtoCall.callService();			
			Logger.verifyEquals("false", ipareaauthmanagerequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyIsContains("Country不能为空", ipareaauthmanagerequestdtoCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_IpAreaAuthManageRequestDto_005() {
		Logger.start(true,"Province不能为空为空,失败");
		try {
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer userid=uc.getUserid();
			ipareaauthmanagerequestdtoBean.setCountry("China");
			ipareaauthmanagerequestdtoCall.setData(ipareaauthmanagerequestdtoBean);
			ipareaauthmanagerequestdtoCall.callService();			
			Logger.verifyEquals("false", ipareaauthmanagerequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyIsContains("Province不能为空", ipareaauthmanagerequestdtoCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_IpAreaAuthManageRequestDto_006() {
		Logger.start(true,"City不能为空,失败");
		try {
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer userid=uc.getUserid();
			ipareaauthmanagerequestdtoBean.setCountry("China");
			ipareaauthmanagerequestdtoBean.setProvince("Shanghai");
			ipareaauthmanagerequestdtoCall.setData(ipareaauthmanagerequestdtoBean);
			ipareaauthmanagerequestdtoCall.callService();			
			Logger.verifyEquals("false", ipareaauthmanagerequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyIsContains("City不能为空", ipareaauthmanagerequestdtoCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}